﻿@model System.Data.DataTable           
@using Jb.Web.Utility;
@using Jb.Common.Extensions;
@using Jb.Common.DB;
@{
    bool _ShowForEmployer = NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SHOW_EDIT_LINK]);
    bool _ShowApplicationCount = Jb.Common.DB.NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SHOW_APPLICATION_COUNT]);
    bool _ShowSendToFriend = ViewData[AppConstants.ViewDataKeys.SHOW_SEND_TO_FRIEND] == null ? true : NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.SHOW_SEND_TO_FRIEND]);
    bool _HideAddToFavorite = ViewData[AppConstants.ViewDataKeys.HIDE_ADD_TO_FAVORITE] == null ? true : NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.HIDE_ADD_TO_FAVORITE]);
    bool _ShowRemoveFavorite = NullHandler.GetBoolean(ViewData[AppConstants.ViewDataKeys.REMOVE_FROM_FAVORITE]);
    
    int _TotalRecordToDisplay = Model == null ? 0 : Model.Rows.Count;
    String _LinkTarget = _ShowForEmployer ? " target='_blank'" : String.Empty;
    String _CompanyKey = NullHandler.GetString(ViewData[AppConstants.ViewDataKeys.COMPANY_KEY]);
    String _ListType = WebUtil.GetQueryStringValue("Type");

    List<int> _FavoriteJobs = new List<int>();
    if (UserInfo.IsJobSeeker)
    {
        Jb.Domain.JbEntities context = new Jb.Domain.JbEntities();
        _FavoriteJobs = (from P in context.FavoriteJobs where P.UserID == SessionCache.CurrentUser.ID select P.JobID).ToList();
    }
}

@if (_TotalRecordToDisplay > 0)
{   
    <div>
    @for (int i = 0; i < Model.Rows.Count; i++)
    {
        System.Data.DataRow _Row = Model.Rows[i];
        int _JobID = NullHandler.GetInt(_Row["ID"]);
        String _ComapnyLogo = NullHandler.GetString(_Row["CompanyLogo"]);
        String _ComapnyName = NullHandler.GetString(_Row["CompanyName"]);
        String _JobUrl = NullHandler.GetString(_Row["Url"]);
        DateTime _EndDate = NullHandler.GetDateTime(_Row["EndDate"]);
        String _ExpireMessage = _EndDate >= DateTime.Now ? "Expires On " : "Expired On ";
        String _ExpireAlert = _EndDate < DateTime.Now ? "<span class=\"label label-warning\">Job Expired</span>" : String.Empty;
                
        <div class="jb-job">
            <div>
                <h2><small><a href="@Url.JobDetailsUrl(_JobID, _JobUrl, _CompanyKey)"@(_LinkTarget)>@Html.FormatData(_Row["Title"])</a></small></h2>
                @(Html.Raw(_ExpireAlert))
            </div>
            @*<div class="clearfix"></div>*@
            <div class="jb-label-hint">
                <a href="@Url.PublicUrl(String.Empty, NullHandler.GetString(_Row["CompanyUrl"]))">@NullHandler.GetString(_Row["CompanyName"])</a><br />
                Published On @Html.FormatData(_Row["PostDate"]) and @_ExpireMessage @Html.FormatData(_EndDate)  
            </div>
            
            @*<div class="clearfix"></div>*@
            <div class="para">
                @Html.Raw(Html.FormatData(WebUtil.GetFormattedJobDescription(NullHandler.GetString(_Row["Description"]))))
            </div>
            <div>
                <a class="btn btn-primary btn-mini" href="@Url.JobDetailsUrl(_JobID, _JobUrl, _CompanyKey)"@(_LinkTarget)><i class="icon-star icon-white"></i> See Details</a>
                @if(!_ShowForEmployer && _ShowSendToFriend){ 
                <a class="btn btn-mini" href="javascript:void(0);" onclick="ConfirmSendToFriend(@_JobID, this);"><i class="icon-envelope"></i> Send to Friend</a>
                }
                @if(_ShowApplicationCount){
                <a href="/Private/JobApplication/List/@(_JobID)" class="btn btn-mini"><i class="icon-envelope"></i> Applications (@NullHandler.GetInt(_Row["ApplicationCount"]))</a>
                }
                @if (_ShowForEmployer) {
                    String editUrl = "/Private/Job/Edit/" + _JobID;
                    if(!_ListType.IsNullOrEmpty()){
                        editUrl += "?Type=" + _ListType; 
                    }
                    <a href="javascript:void(0);" class="btn btn-mini delete-job" delete-job-id='@_JobID'><i class="icon-remove"></i> Delete</a>
                    
                    <a href="@(editUrl)" class="btn btn-mini"><i class="icon-edit"></i> Edit</a>
                }
                @if (!_HideAddToFavorite)
                {
                    if (_FavoriteJobs.Contains(_JobID))
                    {
                        <button class="btn btn-mini disabled" type="button"><i class="icon-star"></i> Added to Favorite</button>
                    }
                    else
                    {
                        <button class="btn btn-mini" type="button" onclick="AddToFavoriteJob(@_JobID, this);"><i class="icon-star"></i> Add to Favorite</button>
                    }
                }
                @if(_ShowRemoveFavorite){
                    <a href="javascript:void(0);" class="btn btn-mini" onclick="RemoveFromFavorite(@_JobID, this)"><i class="icon-remove"></i> Remove from Favorite</a>
                }
            </div>
        </div>
        @*<div class="clearfix"></div>*@
    } 
    </div>
}
@*End of if _TotalRecordToDisplay > 0*@

